package syn_demo1;

public class Demo1 {

    static class SynObj implements Runnable{

        Object lockTarget = new Object();

        @Override
        public void run() {
            synchronized (lockTarget){
                System.out.println("线程"+ Thread.currentThread().getName() + "开始");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程"+ Thread.currentThread().getName() + "结束");
            }
        }

    }

    public static void main(String[] args) {
        SynObj instance1 = new SynObj();
        SynObj instance2 = new SynObj();
        Thread t1 = new Thread(instance1);
        Thread t2 = new Thread(instance2);
        t1.start();
        t2.start();
    }
}
